import info.gridworld.actor.Actor;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.awt.Color;
import java.util.ArrayList;

/**
 * A <code>KingCrab</code> looks at a limited set of neighbors when it eats and moves.
 * <br />
 * This class is not tested on the AP CS A and AB exams.
 */
public class KingCrab extends CrabCritter
{
    public KingCrab()
    {
        setColor(Color.YELLOW);
    }

    
    /**
     * check and move the KingCrab
     * @param a
     * @return
     */
    private boolean moveOneMoreAway(Actor a)
    {
    	Grid<Actor> g = getGrid();
    	Location loc = a.getLocation().getAdjacentLocation(getDirection() + Location.AHEAD);
		if (g.isValid(loc))
		{
			a.moveTo(loc);
			return true;
		}
    	return false;
    }
    
    /**
     *  A KingCrab causes each actor that it processes to move one location further away from the KingCrab. 
     *  If the actor cannot move away, the KingCrab removes it from the grid
     * @param actors the actors to be processed
     */
    public void processActors(ArrayList<Actor> actors)
    {
        for (Actor a : actors)
        {
        	if (!moveOneMoreAway(a))
        	{
        		a.removeSelfFromGrid();
        	}
        }
    }
    

    
    
}
